package com.wkg.lotterysystem.dao.mapper;

import com.wkg.lotterysystem.dao.dataobject.PrizeDO;
import jakarta.validation.constraints.NotNull;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PrizeMapper {

    @Insert("insert into prize (name,image_url,price,description) " +
            "values (#{name},#{imageUrl},#{price},#{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insert(PrizeDO prizeDO);


    @Select("select count(*) from prize")
    int count();

    @Select("select * from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeDO> selectPrizeList(@Param("offset") Integer offset,
                                  @Param("pageSize") Integer pageSize);

    @Select("<script>" +
            " SELECT id FROM prize " +
            " WHERE id IN " +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            "  #{item}" +
            " </foreach>" +
            " </script>")
    List<Integer> selectExistByIds(@Param("items") List<Integer> ids);


    @Select("<script>" +
            " SELECT * FROM prize " +
            " WHERE id IN " +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            "  #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDO> batchSelectByIds(@Param("items") List<Integer> prizeIds);

    @Select("select * from prize where id=#{id}")
    PrizeDO selectById(@Param("id") Integer id);
}


